package cn.softcits.network.one;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-18 11:17 AM
 */
public class Server {
    public static List<Socket> socketList
            = Collections.synchronizedList(new ArrayList<>());
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8080);
        while(true) {
            System.out.println("set up connection.");
            Socket s = ss.accept();
            //
            socketList.add(s);
            new Thread(new ServerThread(s)).start();

//            OutputStream os = s.getOutputStream();
//            InetAddress ip = s.getInetAddress();
//            String ipAddress = ip.getHostAddress();
//            String hostName = ip.getHostName();
//            String content = "生日快乐! from server.";
//            System.out.println("A client is accessing..." + ipAddress + ": " + hostName);
//            os.write(content.getBytes("UTF-8"));
//            //os.close();

        }
    }
}
